package treeSet;

import java.util.*;

/**
 * An item with a description and a part number.
 */
public class Item implements Comparable<Item> {

    private int number;
    private String description;

    /**
     * Constructs an item.
     * @param number the item's part number.
     * @param description the item's description.
     */
    public Item(int number, String description) {
        this.number = number;
        this.description = description;
    }

    /**
     * Gets the description of this item.
     * @return the description
     */
    public String getDescription() {
        return this.description;
    }

    public String toString() {
        return "[part number =" + this.number + ", description = " +
            this.description + "]";
    }

    public boolean equals(Object other) {
        if (this == other) return true;
        if (other == null) return false;
        if (getClass() != other.getClass()) return false;

        Item item = (Item) other;
        return Objects.equals(this.description, item.description) &&
            this.number == item.number;
    }

    public int hashCode() {
        return Objects.hash(number, description);
    }

    public int compareTo(Item other) {
        return Integer.compare(number, other.number);
    }
}
